<template>
  <el-container>
    <el-main>
      <app-table
      :page-data="pageData"
      :table-columns="tableColumns"
      v-on:currentChange="handleCurrentChange"/>
    </el-main>
  </el-container>
</template>

<script>
import {logList} from '@/http/AppApi'
import AppTable from '@/components/AppTable'
export default {
  data () {
    return {
      tableData: [],
      pageData: {},
      param: {},
      tableColumns: [
        { label: '操作名', prop: 'action' },
        { label: '开始时间', prop: 'startTime', formatter: this.formatterColumn },
        { label: '用户ID', prop: 'userId' },
        { label: '客户端IP', prop: 'clientIp' },
        { label: '来源', prop: 'source' }
      ]
    }
  },
  components: {
    AppTable
  },
  mounted () {
    this.getTableData()
  },
  methods: {
    getTableData (param) {
      logList(param).then(resp => {
        if (resp.code && resp.code === '200') {
          this.pageData = resp.data
          if (this.pageData.items && this.pageData.items instanceof Array) {
            this.tableData = this.pageData.items
          }
        } else {
          this.$message({
            type: 'info',
            message: resp.message
          })
        }
      })
    },
    handleCurrentChange (val) {
      let param = {
        offset: (val - 1) * 10
      }
      this.getTableData(param)
    },
    formatterColumn (row, column) {
      if (row && row.startTime) {
        let time = row.startTime
        return this.$moment(time).format('YYYY-MM-DD HH:mm')
      } else {
        return ''
      }
    }
  },
  computed: {},
  watch: {}
}
</script>
<style>
</style>
